<?php
//分页函数
function paging($table, $url, $where = ''){
	$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
	$pagesize = isset($_REQUEST['pagesize']) ? $_REQUEST['pagesize'] : pagesize;
	$url .= $pagesize == pagesize ? '' : '&pagesize='.$pagesize;
	$recordcount = $GLOBALS['db']->getOne("select count(*) from `{$table}` where 1 {$where}");
	$pagecount = ceil($recordcount / $pagesize);
	$limit = "limit ".(($page - 1) * $pagesize).",{$pagesize}";
	$order = isset($_REQUEST['order']) ? $_REQUEST['order'] : '';
	$url .= $order ? '&order='.$order : '';
	$order = explode('_', $order);
	$order = count($order) > 1 ? "order by {$order[0]} {$order[1]}" : '';
	$data['page'] = $page;
	$data['pagesize'] = $pagesize;
	$data['recordcount'] = $recordcount;
	$data['pagecount'] = $pagecount;
	$data['list'] = $GLOBALS['db']->getAll("select * from `{$table}` where 1 {$where} {$order} {$limit}");
	$data['previous'] = $page <= 1 ? 'javascript:;' : $url.'&page='.($page - 1);
	$data['first'] = $page <= 1 ? 'javascript:;' : $url.'&page=1';
	$data['next'] = $page >= $pagecount ? 'javascript:;' : '&page='.($page + 1);
	$data['last'] = $page >= $pagecount ? 'javascript:;' : '&page='.$pagecount;
	$data['url'] = $url;
	return $data;
}

function get_goods_attr(){
	$r = $GLOBALS['db']->getAll("select * from m_area order by area_id");
	foreach($r as $v){
		$data['area_list'][$v['area_id']] = $v['area_c_name'];
	}
	$r = $GLOBALS['db']->getAll("select * from m_color order by color_id");
	foreach($r as $v){
		$data['color_list'][$v['color_id']] = $v['color_c_name'];
	}
	$r = $GLOBALS['db']->getAll("select * from m_type order by type_id");
	foreach($r as $v){
		$data['type_list'][$v['type_id']] = $v['type_c_name'];
	}
	$r = $GLOBALS['db']->getAll("select * from m_models order by models_id");
	foreach($r as $v){
		$data['models_list'][$v['models_id']] = $v['models_c_name'];
	}
	$r = $GLOBALS['db']->getAll("select * from m_condition order by condition_id");
	foreach($r as $v){
		$data['condition_list'][$v['condition_id']] = $v['condition_c_name'];
	}
	$r = $GLOBALS['db']->getAll("select * from m_displacement order by displacement_id");
	foreach($r as $v){
		$data['displacement_list'][$v['displacement_id']] = $v['displacement_c_name'];
	}
	$r = $GLOBALS['db']->getAll("select * from m_mileage order by mileage_id");
	foreach($r as $v){
		$data['mileage_list'][$v['mileage_id']] = $v['mileage_c_name'];
	}
	$data['is_enable'] = array('1' => $GLOBALS['lan']['is_enable_yes'], '0' => $GLOBALS['lan']['is_enable_no']);
	for($i = 1995;$i <= date('Y');$i ++){
		$data['buy_year_list'][$i] = $i;
	}
	return $data;
}

